package com.sias.controller;

import com.sias.domain.User;
import com.sias.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2023/5/31 11:36
 */
@Controller
public class UserController {

  @Autowired
  UserService userService;

  @GetMapping("/test")
  @ResponseBody
  public User getUserById(HttpServletRequest request) {
    request.getSession().setAttribute("name","wuwenjie");
    return userService.getUserById(1);
  }

  @GetMapping("/test2")
  @ResponseBody
  public String  getUserById2(HttpServletRequest request) {
    for (Cookie cookie : request.getCookies()) {
      System.out.println(cookie.getName()+"=="+cookie.getValue());
    }

    String name = (String) request.getSession().getAttribute("name");
    return name;
  }

}
